﻿Shader "Running/soldierSkin"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
	}
	SubShader
	{
		Tags { 
			"RenderType"="Opaque" 
			"ShadowRender" = "Soldier"
		}

		LOD 100
		Pass {
			zwrite off

			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#include "UnityCG.cginc"

			struct appdata
			{
				float4 vertex : POSITION;
				float3 normal : NORMAL;
			};

			struct v2f
			{
				float4 vertex : SV_POSITION;
			};
			v2f vert(appdata v)
			{
				v2f o;
				//只平移
				//o.vertex = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0, 0, 0, 1)) + float4(v.vertex.x, v.vertex.y, 0, 0));
				//o.vertex = mul(UNITY_MATRIX_P,
				//	mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1.0))
				//	+ float4(v.vertex.x, v.vertex.y, 0.0, 0.0));

				float4x4 mat1 = UNITY_MATRIX_MV;
				/*
				float4 row1 = mat1[0];
				float4 row2 = mat1[1];
				float4 row3 = mat1[2];
				float4 row4 = mat1[3];
				row1.xyz = float3(1, 0, 0);
				row2.xyz = float3(0, 1, 0);
				row3.xyz = float3(0, 0, 1);
				mat1 = float4x4(row1, row2, row3, row4);
				*/

				//float4 pointSize = float4( (v.vertex.xyz - v.normal)*1.2+v.normal, 1);

				float3 offsetPos = (v.vertex.xyz - v.normal) * 1.2;
				o.vertex = mul(UNITY_MATRIX_P, mul(mat1, float4(v.normal, 1)) + float4(offsetPos, 0));
				return o;
			}

			fixed4 frag(v2f i) : SV_Target
			{
				fixed4 col = fixed4(0, 0, 0, 1);
			return col;
			}
			ENDCG
		}

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			// make fog work
			#pragma multi_compile_fog
			
			#include "UnityCG.cginc"

			struct appdata
			{
				float4 vertex : POSITION;
				float4 color : COLOR;
				float3 normal : NORMAL;
				float2 uv : TEXCOORD0;
			};

			struct v2f
			{
				float4 vertex : SV_POSITION;
				float4 col : COLOR;
				float2 uv : TEXCOORD0;
			};


			
			v2f vert (appdata v)
			{
				v2f o;
				//只平移
				//o.vertex = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0, 0, 0, 1)) + float4(v.vertex.x, v.vertex.y, 0, 0));
				//o.vertex = mul(UNITY_MATRIX_P,
				//	mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1.0))
				//	+ float4(v.vertex.x, v.vertex.y, 0.0, 0.0));
				
				float4x4 mat1 = UNITY_MATRIX_MV;
				/*
				float4 row1 = mat1[0];
				float4 row2 = mat1[1];
				float4 row3 = mat1[2];
				float4 row4 = mat1[3];
				*/
				/*
				row1.xyz = float3(1, 0, 0);
				row2.xyz = float3(0, 1, 0);
				row3.xyz = float3(0, 0, 1);
				*/
				//mat1 = float4x4(row1, row2, row3, row4);

				//v.vertex - float4(v.normal, 0);

				float3 offsetPos = v.vertex.xyz - v.normal;

				float4 centerPoint = mul(UNITY_MATRIX_P, mul(mat1, float4(v.normal, 1))+float4(offsetPos, 0) );
				//o.vertex = float4(centerPoint.xyz + offsetPos*0.2, 1);
				o.vertex = centerPoint;


				//float4x4 mat1 = UNITY_MATRIX_MV;

					//* float4(_ScaleX, _ScaleY, 1.0, 1.0));

				//o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
				//o.vertex = mul( mul( UNITY_MATRIX_VP, unity_ObjectToWorld), v.vertex);

				//o.vertex = mul( mul(UNITY_MATRIX_P, mul( UNITY_MATRIX_V, unity_ObjectToWorld)), v.vertex);

				//o.vertex = mul( mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0, 0, 0, 1))), v.vertex);



				//float4 viewPos = mul(modelViewMat, v.vertex);
				//float4 viewCenter = mul(modelViewMat, v.normal);
				//float3 viewNormal = mul(modelViewMat, float3(0, 0, 1));

				o.col = v.color;
				o.uv = v.uv;

				//float4 offP = mul(UNITY_MATRIX_MV, float4(0, 0, 0, 1)) + float4(v.vertex.x, v.vertex.y, 11, 0);
				//o.vertex = offP;

				//o.col = offP;
				return o;
			}
			

			sampler2D _MainTex;
			fixed4 frag (v2f i) : SV_Target
			{
				//fixed4 texCol = tex2D(_MainTex, i.uv);

				//fixed4 col = i.col * texCol;
				fixed4 col = i.col;
				return col;
			}
			ENDCG
		}
	}
}
